/*
 * Class: DBMTable
 * 
 * Description: Implement the statement used to create the tables in the database.
 * 
 * Version 1.0 M-A Lavoie - 2011-11-11
 * 		Initial implementation
 * 
 * Version 1.1 Mohamed Ali Ayed - 2011-11-16
 * 
 * Version 1.2 Sonny Guenette - 2011-12-09
 * 		Add a UNIQUE constraint to the name in event
 * 
 * Copyright GPP - Genuine People Personality inc.
 * 
 */

package dbManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DBMTable {
	private PreparedStatement m_oPst;

	//*********************************************************
	// Method: createTable
	// Description: Create all the tables used by the program.
	//*********************************************************
	/**
	 * @param p_oCon The connection object
	 * @return true if the tables are successfully created
	 */
	public boolean createTable(Connection p_oCon) {
		try {
			m_oPst = p_oCon.prepareStatement("CREATE TABLE IF NOT EXISTS events (event_id SMALLINT AUTO_INCREMENT," +
					"PRIMARY KEY(event_id), name TINYTEXT, startTime DATETIME," +
					"endTime DATETIME, description TINYTEXT, agenda_id SMALLINT)");
			m_oPst.executeUpdate();
			m_oPst = p_oCon.prepareStatement("CREATE TABLE IF NOT EXISTS agendas" +
					"(agenda_id SMALLINT AUTO_INCREMENT, PRIMARY KEY(agenda_id), name varchar(12) UNIQUE, color SMALLINT )");
			m_oPst.executeUpdate();

		} catch (SQLException ex) {
			Logger lgr = Logger.getLogger(DBMTable.class.getName());
			lgr.log(Level.SEVERE, ex.getMessage(), ex);
			return false;
		} 
		return true;
	}

}